package com.all.ui;

import com.all.widget.gridview.RefreshGridView;
import com.all.widget.listener.OnRefreshListener;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class GridviewActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_grifview);
		
		RefreshGridView gv = (RefreshGridView)findViewById(R.id.gridview); 
        //为GridView设置适配器 
        gv.setAdapter(new MyAdapter(this)); 
        
        gv.setOnRefreshListener(new OnRefreshListener() {
			
			@Override
			public void onRefresh() {
				// TODO Auto-generated method stub
				
			}
		});
	}
	
	
}


//自定义适配器 
class MyAdapter extends BaseAdapter{ 
    //上下文对象 
    private Context context; 
    //图片数组 
    private Integer[] imgs = { 
            R.drawable.scrollview_header, R.drawable.frame_me_newcommunity, R.drawable.qq,
            R.drawable.frame_me_newcommunity, R.drawable.scrollview_header, R.drawable.qq,
            R.drawable.scrollview_header, R.drawable.qq, R.drawable.frame_me_newcommunity,
    }; 
    MyAdapter(Context context){ 
        this.context = context; 
    } 
    public int getCount() { 
        return imgs.length; 
    } 

    public Object getItem(int item) { 
        return item; 
    } 

    public long getItemId(int id) { 
        return id; 
    } 
     
    //创建View方法 
    public View getView(int position, View convertView, ViewGroup parent) { 
         ImageView imageView; 
            if (convertView == null) { 
                imageView = new ImageView(context); 
                imageView.setLayoutParams(new GridView.LayoutParams(75, 75));//设置ImageView对象布局 
                imageView.setAdjustViewBounds(false);//设置边界对齐 
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);//设置刻度的类型 
                imageView.setPadding(8, 8, 8, 8);//设置间距 
            }  
            else { 
                imageView = (ImageView) convertView; 
            } 
            imageView.setImageResource(imgs[position]);//为ImageView设置图片资源 
            return imageView; 
    } 
} 